/**
 * @description crud示例web api
 * @author pan
 */
import { baseMgrApiServer } from '../base-api'
import WinterRequestUtil from '@/utils/WinterRequestUtil'
import WinterUtil from '@/utils/WinterUtil'

const apiBaseUrl = baseMgrApiServer + '/demo/crud'

const apiUrlObj = {
  add: apiBaseUrl,
  page: apiBaseUrl + '/page',
  edit: apiBaseUrl + '/{id}',
  delete: apiBaseUrl + '/{id}'
}

export default {
  /**
   * 新增
   * @param data
   * @returns {Promise<*>}
   */
  async add$ (data) {
    return WinterRequestUtil.bodyPost(apiUrlObj.add, data)
  },
  /**
   * 分页查找
   * @param data
   * @returns {Promise<*>}
   */
  async page$ (data) {
    return WinterRequestUtil.get(apiUrlObj.page, data)
  },
  /**
   * 编辑
   * @param id
   * @param data
   * @returns {Promise<*>}
   */
  async edit$ (id, data) {
    const reqUrl = WinterUtil.formReplacePathVar(apiUrlObj.edit, { id: id })
    return WinterRequestUtil.bodyPut(reqUrl, data)
  },
  /**
   * 删除
   * @param id
   * @returns {Promise<*>}
   */
  async delete$ (id) {
    const reqUrl = WinterUtil.formReplacePathVar(apiUrlObj.delete, { id: id })
    return WinterRequestUtil.delete(reqUrl)
  }
}
